

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/xiaotubiao.png">
  <link rel="icon" href="/img/xiaotubiao.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Qin Zk">
  <meta name="keywords" content="">
  
    <meta name="description" content="微信公众号：数学建模与人工智能 https:&#x2F;&#x2F;github.com&#x2F;QInzhengk&#x2F;Math-Model-and-Machine-Learning ​力扣刷题用的是核心代码模式，而牛客用的是ACM模式；由于ACM竞赛题目的输入数据和输出数据一般有多组（不定），并且格式多种多样，所以，如何处理题目的输入输出是对大家的一项最基本的要求。这也是困扰初学者的一大问题。 一、Java1. 输入:12i">
<meta property="og:type" content="article">
<meta property="og:title" content="ACM模式之输入输出（Java&#x2F;Python例题）">
<meta property="og:url" content="http://example.com/2022/07/30/ACM%E6%A8%A1%E5%BC%8F%E4%B9%8B%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA%EF%BC%88Java_Python%E4%BE%8B%E9%A2%98%EF%BC%89/index.html">
<meta property="og:site_name" content="幸运藏在努力里">
<meta property="og:description" content="微信公众号：数学建模与人工智能 https:&#x2F;&#x2F;github.com&#x2F;QInzhengk&#x2F;Math-Model-and-Machine-Learning ​力扣刷题用的是核心代码模式，而牛客用的是ACM模式；由于ACM竞赛题目的输入数据和输出数据一般有多组（不定），并且格式多种多样，所以，如何处理题目的输入输出是对大家的一项最基本的要求。这也是困扰初学者的一大问题。 一、Java1. 输入:12i">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/868257b533bf4c85998ac7add44eb15f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcXE3NDIyMzQ5ODQ=,size_11,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/054c0e2aba084e54ada0ec1ce22911d6.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcXE3NDIyMzQ5ODQ=,size_16,color_FFFFFF,t_70,g_se,x_16">
<meta property="article:published_time" content="2022-07-30T08:47:30.602Z">
<meta property="article:modified_time" content="2022-07-30T08:52:35.204Z">
<meta property="article:author" content="Qin Zk">
<meta property="article:tag" content="编程">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/868257b533bf4c85998ac7add44eb15f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcXE3NDIyMzQ5ODQ=,size_11,color_FFFFFF,t_70,g_se,x_16">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>ACM模式之输入输出（Java/Python例题） - 幸运藏在努力里</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.0","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":"ture","follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>

  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Qin&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/article.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="ACM模式之输入输出（Java/Python例题）"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Qin Zk
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-07-30 16:47" pubdate>
          2022年7月30日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    

    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

    <a target="_blank" rel="noopener" href="https://qzkq.github.io" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#64CEAA; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">ACM模式之输入输出（Java/Python例题）</h1>
            
            <div class="markdown-body">
              
              <p><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s?__biz=MzI5MTY1MzU1Mg==&mid=2247487453&idx=1&sn=4659cb0f09714bebafd389a016e152cc&scene=19#wechat_redirect">微信公众号：数学建模与人工智能</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/QInzhengk/Math-Model-and-Machine-Learning">https://github.com/QInzhengk/Math-Model-and-Machine-Learning</a></p>
<p>​力扣刷题用的是核心代码模式，而<strong>牛客用的是ACM模式</strong>；由于ACM竞赛题目的输入数据和输出数据一般有多组（不定），并且格式多种多样，所以，如何处理题目的输入输出是对大家的一项最基本的要求。这也是困扰初学者的一大问题。</p>
<h2 id="一、Java"><a href="#一、Java" class="headerlink" title="一、Java"></a>一、Java</h2><h3 id="1-输入"><a href="#1-输入" class="headerlink" title="1. 输入:"></a>1. 输入:</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.Scanner;<br><span class="hljs-type">Scanner</span> <span class="hljs-variable">sc</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Scanner</span> (System.in);<br></code></pre></td></tr></table></figure>

<p>读一个整数：int n &#x3D; sc.nextInt();<br>读一个字符串：String s &#x3D; sc.next();（以空格作为分隔符）<br>读一个浮点数：double t &#x3D;sc.nextDouble();<br>读一整行：String s &#x3D; sc.nextLine();<br>判断是否有下一个输入可以用sc.hasNext()或sc.hasNextInt()或sc.hasNextDouble()或sc.hasNextLine()</p>
<h3 id="2-输出"><a href="#2-输出" class="headerlink" title="2. 输出"></a>2. 输出</h3><p>System.out.println();&#x2F;&#x2F;换行打印，输出之后会自动换行<br>System.out.print();&#x2F;&#x2F;不换行打印<br>System.out.printf();&#x2F;&#x2F;按格式输出</p>
<h3 id="3-字符串处理-String"><a href="#3-字符串处理-String" class="headerlink" title="3. 字符串处理 String"></a>3. 字符串处理 String</h3><p>String 类用来存储字符串，可以用charAt方法来取出其中某一字节，计数从0开始：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-type">String</span> <span class="hljs-variable">a</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;Hello&quot;</span>; <span class="hljs-comment">// a.charAt(1) = &#x27;e&#x27;</span><br></code></pre></td></tr></table></figure>

<p>用substring方法可得到子串，如上例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">System.out.println(a.substring(<span class="hljs-number">0</span>, <span class="hljs-number">4</span>)) <span class="hljs-comment">// output &quot;Hell&quot;</span><br></code></pre></td></tr></table></figure>

<p>注意第2个参数位置上的字符不包括进来。这样做使得 s.substring(a, b) 总是有 b-a个字符。<br>字符串连接可以直接用 + 号，如</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-type">String</span> <span class="hljs-variable">a</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;Hello&quot;</span>;<br><span class="hljs-type">String</span> <span class="hljs-variable">b</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;world&quot;</span>;<br>System.out.println(a + <span class="hljs-string">&quot;, &quot;</span> + b + <span class="hljs-string">&quot;!&quot;</span>); <span class="hljs-comment">// output &quot;Hello, world!&quot;</span><br></code></pre></td></tr></table></figure>

<p>如想直接将字符串中的某字节改变，可以使用另外的StringBuffer类。</p>
<h3 id="4-高精度"><a href="#4-高精度" class="headerlink" title="4. 高精度"></a>4. 高精度</h3><p>BigInteger和BigDecimal可以说是acmer选择java的首要原因。<br>函数：add, subtract, divide, mod, compareTo等，其中加减乘除模都要求是BigInteger(BigDecimal)和BigInteger(BigDecimal)之间的运算，所以需要把int(double)类型转换为BigInteger(BigDecimal)，用函数BigInteger.valueOf().</p>
<h3 id="5-进制转换"><a href="#5-进制转换" class="headerlink" title="5. 进制转换"></a>5. 进制转换</h3><p>String st &#x3D; Integer.toString(num, base); &#x2F;&#x2F; 把num当做10进制的数转成base进制的st(base &lt;&#x3D; 35).<br>int num &#x3D; Integer.parseInt(st, base); &#x2F;&#x2F; 把st当做base进制，转成10进制的int(parseInt有两个参数,第一个为要转的字符串,第二个为说明是什么进制).<br>BigInter m &#x3D; new BigInteger(st, base); &#x2F;&#x2F; st是字符串，base是st的进制.</p>
<h3 id="6-数组排序"><a href="#6-数组排序" class="headerlink" title="6. 数组排序"></a>6. 数组排序</h3><p>函数：<code>Arrays.sort();</code></p>
<h2 id="二、Python"><a href="#二、Python" class="headerlink" title="二、Python"></a>二、Python</h2><h3 id="1-输入："><a href="#1-输入：" class="headerlink" title="1.输入："></a>1.输入：</h3><p>input为字符串，int强制转换成整形；多组例子使用while</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python">n=<span class="hljs-built_in">int</span>(<span class="hljs-built_in">input</span>()) <span class="hljs-comment">#3</span><br>s=<span class="hljs-built_in">input</span>().split(<span class="hljs-string">&#x27;,&#x27;</span>)  <span class="hljs-comment">#1,2,3</span><br><span class="hljs-keyword">try</span>:<br>    n,m = <span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split()) <span class="hljs-comment">#2 5</span><br>    <span class="hljs-keyword">except</span>:<br>       <span class="hljs-keyword">break</span><br>b = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split())) <span class="hljs-comment">#2 3 5 6 9 </span><br></code></pre></td></tr></table></figure>

<h3 id="2-输出-1"><a href="#2-输出-1" class="headerlink" title="2.输出:"></a>2.输出:</h3><blockquote>
<p>print(*objects, sep&#x3D;’ ‘, end&#x3D;’\n’, file&#x3D;sys.stdout)</p>
</blockquote>
<p>参数的具体含义如下：</p>
<ul>
<li>objects –表示输出的对象。输出多个对象时，需要用 , （逗号）分隔。 </li>
<li>sep – 用来间隔多个对象。 </li>
<li>end –用来设定以什么结尾。默认值是换行符 \n，我们可以换成其他字符。 </li>
<li>file – 要写入的文件对象。</li>
</ul>
<h3 id="3-sort和sorted"><a href="#3-sort和sorted" class="headerlink" title="3.sort和sorted"></a>3.sort和sorted</h3><p>python中列表的内置函数sort（）可以对列表中的元素进行排序，而全局性的sorted（）函数则对所有可迭代的序列都是适用的；并且sort（）函数是内置函数，会改变当前对象，而sorted（）函数只会返回一个排序后的当前对象的副本，而不会改变当前对象。</p>
<h4 id="1、内置函数sort（fun，key，reverse-x3D-False）"><a href="#1、内置函数sort（fun，key，reverse-x3D-False）" class="headerlink" title="1、内置函数sort（fun，key，reverse&#x3D;False）"></a>1、内置函数sort（fun，key，reverse&#x3D;False）</h4><ol>
<li>参数fun是表明此sort函数是基于何种算法进行排序的，一般默认情况下python中用的是归并排序</li>
<li>参数key用来指定一个函数，此函数在每次元素比较时被调用，此函数代表排序的规则，也就是你按照什么规则对你的序列进行排序</li>
<li>参数reverse是用来表明是否逆序，默认的False情况下是按照升序的规则进行排序的，当reverse&#x3D;True时，便会按照降序进行排序</li>
</ol>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment">#coding:utf-8</span><br>list1 = [(<span class="hljs-number">2</span>,<span class="hljs-string">&#x27;huan&#x27;</span>,<span class="hljs-number">23</span>),(<span class="hljs-number">12</span>,<span class="hljs-string">&#x27;the&#x27;</span>,<span class="hljs-number">14</span>),(<span class="hljs-number">23</span>,<span class="hljs-string">&#x27;liu&#x27;</span>,<span class="hljs-number">90</span>)]<br>​<br><span class="hljs-comment">#使用默认参数进行排序，即按照元组中第一个元素进行排序</span><br>list1.sort()<br><span class="hljs-built_in">print</span> list1<br><span class="hljs-comment">#输出结果为[(2, &#x27;huan&#x27;, 23), (12, &#x27;the&#x27;, 14), (23, &#x27;liu&#x27;, 90)]</span><br>​<br><span class="hljs-comment">#使用匿名表达式重写key所代表的函数,按照元组的第二个元素进行排序</span><br>list1.sort(key=<span class="hljs-keyword">lambda</span> x:(x[<span class="hljs-number">1</span>]))<br><span class="hljs-built_in">print</span> list1<br>​<br><span class="hljs-comment">#[(2, &#x27;huan&#x27;, 23), (23, &#x27;liu&#x27;, 90), (12, &#x27;the&#x27;, 14)]</span><br>​<br><span class="hljs-comment">#使用匿名函数重写key所代表的函数，先按照元组中下标为2的进行排序，</span><br><span class="hljs-comment"># 对于下标2处元素相同的，则按下标为0处的元素进行排序</span><br>list1.sort(key=<span class="hljs-keyword">lambda</span> x:(x[<span class="hljs-number">2</span>],x[<span class="hljs-number">0</span>]))<br><span class="hljs-built_in">print</span> list1<br><span class="hljs-comment">#[(12, &#x27;the&#x27;, 14), (2, &#x27;huan&#x27;, 23), (23, &#x27;liu&#x27;, 90)]</span><br></code></pre></td></tr></table></figure>

<h4 id="2、全局函数sorted（）"><a href="#2、全局函数sorted（）" class="headerlink" title="2、全局函数sorted（）"></a>2、全局函数sorted（）</h4><blockquote>
<p>sorted(iterable, key&#x3D;None, reverse&#x3D;False)</p>
</blockquote>
<p>对于sorted（）函数中key的重写，和sort（）函数中是一样的，所以刚刚对于sort（）中讲解的方法，都是适用于sorted（）函数。<br><img src="https://img-blog.csdnimg.cn/868257b533bf4c85998ac7add44eb15f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcXE3NDIyMzQ5ODQ=,size_11,color_FFFFFF,t_70,g_se,x_16" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="4-幂运算："><a href="#4-幂运算：" class="headerlink" title="4.幂运算："></a>4.幂运算：</h3><p>**</p>
<h3 id="5-index"><a href="#5-index" class="headerlink" title="5.index"></a>5.index</h3><p>Python index() 方法检测字符串中是否包含子字符串 str ，如果指定 beg（开始） 和 end（结束） 范围，则检查是否包含在指定范围内，该方法与 python find()方法一样，只不过如果str不在 string中会报一个异常。<br>index()方法语法：</p>
<blockquote>
<p>str.index(str, beg&#x3D;0,end&#x3D;len(string))</p>
</blockquote>
<p>参数:</p>
<ul>
<li>str – 指定检索的字符串 </li>
<li>beg – 开始索引，默认为0。 </li>
<li>end – 结束索引，默认为字符串的长度。</li>
</ul>
<p>返回值：如果包含子字符串返回开始的索引值，否则抛出异常。</p>
<h3 id="6-any"><a href="#6-any" class="headerlink" title="6.any"></a>6.any</h3><p>any(iterable)：参数iterable – 元组或列表。<br>返回值:如果都为空、0、false，则返回false，如果不都为空、0、false，则返回true。</p>
<h3 id="7-isdigit-方法"><a href="#7-isdigit-方法" class="headerlink" title="7.isdigit()方法"></a>7.isdigit()方法</h3><p>isdigit() 方法检测字符串是否只由数字组成，只对 0 和 正数有效。</p>
<h3 id="8-浮点数输出"><a href="#8-浮点数输出" class="headerlink" title="8.浮点数输出"></a>8.浮点数输出</h3><h4 id="1、格式化输出"><a href="#1、格式化输出" class="headerlink" title="1、格式化输出"></a>1、格式化输出</h4><ul>
<li>%f ——保留小数点后面六位有效数字 </li>
<li>%.3f，保留3位小数位</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;%f&#x27;</span> % <span class="hljs-number">1.11</span>)  <span class="hljs-comment"># 默认保留6位小数</span><br><span class="hljs-number">1.110000</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;%.1f&#x27;</span> % <span class="hljs-number">1.11</span>)  <span class="hljs-comment"># 取1位小数</span><br><span class="hljs-number">1.1</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;%d,%d&quot;</span>%(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>))<br><span class="hljs-number">1</span>,<span class="hljs-number">2</span><br></code></pre></td></tr></table></figure>
<h4 id="2、format-格式化函数"><a href="#2、format-格式化函数" class="headerlink" title="2、format 格式化函数"></a>2、format 格式化函数</h4><p>格式化字符串函数 str.format()，基本语法是通过 {} 和 : 来代替以前的 % 。format 函数可以接受不限个参数，位置可以不按顺序。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#123;&#125; &#123;&#125;&quot;</span>.<span class="hljs-built_in">format</span>(<span class="hljs-string">&quot;hello&quot;</span>, <span class="hljs-string">&quot;world&quot;</span>))    <span class="hljs-comment"># 不设置指定位置，按默认顺序</span><br>hello world<br> <br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#123;0&#125; &#123;1&#125;&quot;</span>.<span class="hljs-built_in">format</span>(<span class="hljs-string">&quot;hello&quot;</span>, <span class="hljs-string">&quot;world&quot;</span>))  <span class="hljs-comment"># 设置指定位置</span><br>hello world<br> <br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#123;1&#125; &#123;0&#125; &#123;1&#125;&quot;</span>.<span class="hljs-built_in">format</span>(<span class="hljs-string">&quot;hello&quot;</span>, <span class="hljs-string">&quot;world&quot;</span>))  <span class="hljs-comment"># 设置指定位置</span><br>world hello world<br><br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#123;:.2f&#125;&quot;</span>.<span class="hljs-built_in">format</span>(<span class="hljs-number">3.1415926</span>))<br><span class="hljs-number">3.14</span><br></code></pre></td></tr></table></figure>

<h4 id="3、内置round-number-ndigits"><a href="#3、内置round-number-ndigits" class="headerlink" title="3、内置round(number[, ndigits])"></a>3、内置round(number[, ndigits])</h4><ul>
<li>number - 这是一个数字表达式。 </li>
<li>ndigits - 表示从小数点到最后四舍五入的位数。默认值为0。</li>
<li>该方法返回x的小数点舍入为n位数后的值。</li>
</ul>
<h3 id="9-set"><a href="#9-set" class="headerlink" title="9.set"></a>9.set</h3><p><img src="https://img-blog.csdnimg.cn/054c0e2aba084e54ada0ec1ce22911d6.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcXE3NDIyMzQ5ODQ=,size_16,color_FFFFFF,t_70,g_se,x_16" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<ul>
<li><p>交集 &amp; : x&amp;y，返回一个新的集合，包括同时在集合 x 和y中的共同元素。 </p>
</li>
<li><p>并集 | : x|y，返回一个新的集合，包括集合 x 和<br>y 中所有元素。</p>
</li>
<li><p>差集 - : x-y，返回一个新的集合,包括在集合 x 中但不在集合 y 中的元素。 </p>
</li>
<li><p>补集 ^ : x^y，返回一个新的集合，包括集合 x 和 y 的非共同元素。</p>
</li>
</ul>
<h3 id="10-ord"><a href="#10-ord" class="headerlink" title="10.ord()"></a>10.ord()</h3><p>ord() 函数是 chr() 函数（对于 8 位的 ASCII 字符串）的配对函数，它以一个字符串（Unicode 字符）作为参数，返回对应的 ASCII 数值，或者 Unicode 数值。</p>
<h2 id="三、编程题"><a href="#三、编程题" class="headerlink" title="三、编程题"></a>三、编程题</h2><h3 id="1、矩阵元素相乘"><a href="#1、矩阵元素相乘" class="headerlink" title="1、矩阵元素相乘"></a>1、矩阵元素相乘</h3><p>A[n,m]是一个n行m列的矩阵，a[i,j]表示A的第i行j列的元素，定义x[i,j]为A的第i行和第j列除了a[i,j]之外所有元素(共n+m-2个)的乘积，即x[i,j]&#x3D;a[i,1]<em>a[i,2]</em>…<em>a[i,j-1]</em>…*a[i,m]*a[1,j]*a[2,j]…*a[i-1,j]*a[i+1,j]…*a[n,j],现输入非负整形的矩阵A[n,m]，求MAX(x[i,j])，即所有的x[i,j]中的最大值。<br><strong>输入描述:</strong></p>
<blockquote>
<p>第一行两个整数n和m。之后n行输入矩阵，均为非负整数。</p>
</blockquote>
<p><strong>输出描述:</strong></p>
<blockquote>
<p>一行输出答案。</p>
</blockquote>
<p>示例1<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">3</span> <span class="hljs-number">5</span><br><span class="hljs-number">5</span> <span class="hljs-number">1</span> <span class="hljs-number">8</span> <span class="hljs-number">5</span> <span class="hljs-number">2</span><br><span class="hljs-number">1</span> <span class="hljs-number">3</span> <span class="hljs-number">10</span> <span class="hljs-number">3</span> <span class="hljs-number">3</span><br><span class="hljs-number">7</span> <span class="hljs-number">8</span> <span class="hljs-number">5</span> <span class="hljs-number">5</span> <span class="hljs-number">16</span><br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">358400</span><br></code></pre></td></tr></table></figure>

<p>Java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.Scanner;<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Main</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span>&#123;<br>        <span class="hljs-type">Scanner</span> <span class="hljs-variable">sc</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Scanner</span>(System.in);<br>        <span class="hljs-keyword">while</span>(sc.hasNext())&#123;<br>            <span class="hljs-type">int</span> <span class="hljs-variable">n</span> <span class="hljs-operator">=</span> sc.nextInt();<br>            <span class="hljs-type">int</span> <span class="hljs-variable">m</span> <span class="hljs-operator">=</span> sc.nextInt();<br>            <span class="hljs-type">int</span>[][] a = <span class="hljs-keyword">new</span> <span class="hljs-title class_">int</span>[n][m];<br>            <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> i=<span class="hljs-number">0</span>;i&lt;n;i++)&#123;<br>                <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> j=<span class="hljs-number">0</span>;j&lt;m;j++)&#123;<br>                    a[i][j] = sc.nextInt();<br>                &#125;<br>            &#125;<br>            <span class="hljs-type">int</span> max=<span class="hljs-number">0</span>;<br>            <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> i=<span class="hljs-number">0</span>;i&lt;n;i++)&#123;<br>                <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> j=<span class="hljs-number">0</span>;j&lt;m;j++)&#123;<br>                  <span class="hljs-type">int</span> res=<span class="hljs-number">1</span>;<br>                    <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> k=<span class="hljs-number">0</span>;k&lt;m;k++)&#123;<br>                        <span class="hljs-keyword">if</span>(k!=j)&#123;<br>                            res*=a[i][k];<br>                        &#125; <br>                    &#125;<br>                    <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> k=<span class="hljs-number">0</span>;k&lt;n;k++)&#123;<br>                        <span class="hljs-keyword">if</span>(k!=i)&#123;<br>                            res*=a[k][j];<br>                        &#125;<br>                    &#125;<br>                    <span class="hljs-keyword">if</span>(max&lt;res)&#123;<br>                        max=res;<br>                    &#125;<br>                &#125;<br>            &#125; <br>            System.out.println(max);  <br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>Python</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:<br>    <span class="hljs-keyword">try</span>:<br>        n,m = <span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split())<br>    <span class="hljs-keyword">except</span>:<br>       <span class="hljs-keyword">break</span><br>    a = []<br>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n):<br>        b = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split()))<br>        a.append(b)   <br>    ma = <span class="hljs-number">0</span><br>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n):<br>        <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(m):<br>            res=<span class="hljs-number">1</span><br>            <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(m):<br>                <span class="hljs-keyword">if</span> k!=j:<br>                    res*=a[i][k]<br>            <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n):<br>                <span class="hljs-keyword">if</span> k!=i:<br>                    res*=a[k][j]<br>            <span class="hljs-keyword">if</span> ma&lt;res:<br>                ma=res                <br>    <span class="hljs-built_in">print</span>(ma)<br></code></pre></td></tr></table></figure>

<h3 id="2、有序数组去重"><a href="#2、有序数组去重" class="headerlink" title="2、有序数组去重"></a>2、有序数组去重</h3><p>给定一个字符串，字符串是有序的整数集合，逗号相连，移除相同的数字，使每个数字只出现一次，输出最终的数字个数。<br><strong>输入描述:</strong></p>
<blockquote>
<p>1,2,2</p>
</blockquote>
<p><strong>输出描述:</strong></p>
<blockquote>
<p>2</p>
</blockquote>
<p>示例1<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">2</span><br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">2</span><br></code></pre></td></tr></table></figure>

<p>示例2<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span><br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">5</span><br></code></pre></td></tr></table></figure>

<p><strong>备注:</strong><br>有序整数字符串集合请在控制台一行内完成输入，并用英文逗号(,)相隔，如：1,2,2<br>Java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.Scanner;<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Main</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String arg[])</span>&#123;<br>        <span class="hljs-type">Scanner</span> <span class="hljs-variable">sc</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Scanner</span>(System.in);<br>        String[] str=sc.nextLine().split(<span class="hljs-string">&quot;,&quot;</span>); <br>        <span class="hljs-type">int</span> <span class="hljs-variable">count</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; str.length-<span class="hljs-number">1</span>; i++) &#123;<br>            <span class="hljs-keyword">if</span> (str[i].equals(str[i+<span class="hljs-number">1</span>]))&#123;<br>                count++;<br>            &#125;<br>        &#125;<br>        System.out.println(str.length-count);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>Python</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">s=<span class="hljs-built_in">input</span>().split(<span class="hljs-string">&#x27;,&#x27;</span>)<br>s=<span class="hljs-built_in">set</span>(s)<br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">len</span>(s))<br></code></pre></td></tr></table></figure>

<h3 id="3、最大子序列和"><a href="#3、最大子序列和" class="headerlink" title="3、最大子序列和"></a>3、最大子序列和</h3><p>给一个长度为N的序列a1,a2,…,an,求最大连续和。也即，寻找1&lt;&#x3D;i&lt;&#x3D;j&lt;&#x3D;N,使得ai+…+aj尽量大。<br><strong>输入描述:</strong></p>
<blockquote>
<p>一行, 整数序列, 逗号分隔</p>
</blockquote>
<p><strong>输出描述:</strong></p>
<blockquote>
<p>一行, 整数, 表示最大子序列和</p>
</blockquote>
<p>示例1<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">1</span>, <span class="hljs-number">2</span>, -<span class="hljs-number">5</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span><br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">7</span><br></code></pre></td></tr></table></figure>

<p>Java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.util.Scanner;<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Main</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String arg[])</span>&#123;<br>        <span class="hljs-type">Scanner</span> <span class="hljs-variable">sc</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Scanner</span> (System.in);<br>        String[] str=sc.nextLine().replace(<span class="hljs-string">&quot; &quot;</span>,<span class="hljs-string">&quot;&quot;</span>).split(<span class="hljs-string">&quot;,&quot;</span>);<br>        <span class="hljs-type">int</span>[] a = <span class="hljs-keyword">new</span> <span class="hljs-title class_">int</span>[str.length];<br>        <span class="hljs-type">int</span> <span class="hljs-variable">k</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">for</span> (String temp : str) &#123;<br>            a[k++] = Integer.parseInt(String.valueOf(temp));<br>        &#125;<br>        <span class="hljs-keyword">if</span>(a.length==<span class="hljs-number">1</span>)&#123;<br>            System.out.print(a[<span class="hljs-number">0</span>]);<br>        &#125;<span class="hljs-keyword">else</span>&#123;<br>          <span class="hljs-type">int</span> temp=<span class="hljs-number">0</span>,ma=a[<span class="hljs-number">0</span>];<br>            <span class="hljs-keyword">for</span>(<span class="hljs-type">int</span> i:a)&#123;<br>                temp=Math.max(temp+i,i);<br>                ma=Math.max(ma,temp);<br>            &#125;<br>            System.out.print(ma);<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>Python</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python">A=<span class="hljs-built_in">list</span>(<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().strip().split(<span class="hljs-string">&#x27;,&#x27;</span>)))<br>temp=<span class="hljs-number">0</span><br>ma=A[<span class="hljs-number">0</span>]<br><span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> A:<br>    temp=<span class="hljs-built_in">max</span>(a+temp,a)<br>    ma=<span class="hljs-built_in">max</span>(temp,ma)<br><span class="hljs-built_in">print</span>(ma)<br></code></pre></td></tr></table></figure>

<h3 id="4、回文串"><a href="#4、回文串" class="headerlink" title="4、回文串"></a>4、回文串</h3><p>回文串是指字符串无论从左读还是从右读，所读的顺序是一样的；简而言之，回文串是左右对称的。<br>现给定一个字符串，求出它的最长回文子串。你可以假定只有一个满足条件的最长回文串。<br><strong>输入描述:</strong></p>
<blockquote>
<p>一行, 字符串</p>
</blockquote>
<p><strong>输出描述:</strong></p>
<blockquote>
<p>一行, 字符串</p>
</blockquote>
<p>示例1<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python">yabccbau<br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python">abccba<br></code></pre></td></tr></table></figure>

<p>Python</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs python">st=<span class="hljs-built_in">input</span>()<br>a=<span class="hljs-string">&#x27;&#x27;</span><br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(st)):<br>    <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(i+<span class="hljs-number">1</span>,<span class="hljs-built_in">len</span>(st)+<span class="hljs-number">1</span>):<br>        s=st[i:j]<br>        <span class="hljs-keyword">if</span>(s==s[::-<span class="hljs-number">1</span>]):<br>            <span class="hljs-keyword">if</span>(<span class="hljs-built_in">len</span>(a)&lt;<span class="hljs-built_in">len</span>(s)):<br>                a=s<br><span class="hljs-built_in">print</span>(a)<br></code></pre></td></tr></table></figure>

<h3 id="5、变形词"><a href="#5、变形词" class="headerlink" title="5、变形词"></a>5、变形词</h3><p>对于两个字符串A和B，如果A和B中出现的字符种类相同且每种字符出现的次数相同，则A和B互为变形词，请设计一个高效算法，检查两给定串是否互为变形词。<br>给定两个字符串A和B，请返回一个bool值，代表他们是否互为变形词。<br><strong>输入描述:</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python">两行，每行各一个字符串s，s长度小于<span class="hljs-number">1000</span><br></code></pre></td></tr></table></figure>

<p><strong>输出描述:</strong></p>
<blockquote>
<p>bool 值</p>
</blockquote>
<p>示例1<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs python">bcbc<br>cbcb<br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">1</span><br></code></pre></td></tr></table></figure>

<p>Python</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs python">s1=<span class="hljs-built_in">input</span>()<br>s2=<span class="hljs-built_in">input</span>()<br>st1=[]<br>st2=[]<br><span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(s1)!=<span class="hljs-built_in">len</span>(s2):<br>    <span class="hljs-built_in">print</span>(<span class="hljs-number">0</span>)<br><span class="hljs-keyword">else</span>:<br>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(s1)):<br>        <span class="hljs-keyword">if</span> s1[i] <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> st1:<br>            st1.append(s1[i])<br>    <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(s2)):<br>        <span class="hljs-keyword">if</span> s2[j] <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> st2:<br>            st2.append(s2[j])<br>    flag=<span class="hljs-number">0</span><br>    <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(st1)):<br>        <span class="hljs-keyword">if</span> s1.count(st1[k])!=s2.count(st1[k]):<br>            flag=<span class="hljs-number">1</span><br>            <span class="hljs-built_in">print</span>(<span class="hljs-number">0</span>)<br>            <span class="hljs-keyword">break</span><br>    <span class="hljs-keyword">if</span>(flag==<span class="hljs-number">0</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-number">1</span>) <br></code></pre></td></tr></table></figure>

<h3 id="6、连续质数表示"><a href="#6、连续质数表示" class="headerlink" title="6、连续质数表示"></a>6、连续质数表示</h3><p>一些正数能被表示成一个或者多个连续质数的和。那一个数会有多少种这样的表示方式呢？比如说数字41能有3种表示方式：2+3+5+7+11+13，11+13+17，和41；数字3只有本身这一种表示方式；而20没有这样的表示方式。写一个程序生成给定数字的表示方式数量吧。数字大小范围从2到10，000。<br><strong>输入描述:</strong></p>
<blockquote>
<p>一行，包含一个2到10000的正整数</p>
</blockquote>
<p><strong>输出描述:</strong></p>
<blockquote>
<p>一行, 非负整数, 给定数字的表示方式数量</p>
</blockquote>
<p>示例1<br>输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">41</span><br></code></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-number">3</span><br></code></pre></td></tr></table></figure>

<p>Python</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">def</span> <span class="hljs-title function_">IsPrime</span>(<span class="hljs-params">num</span>):<br>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>,num):<br>        <span class="hljs-keyword">if</span> num%i==<span class="hljs-number">0</span>:<br>            <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span><br>n=<span class="hljs-built_in">int</span>(<span class="hljs-built_in">input</span>())<br>a=[]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>,n+<span class="hljs-number">1</span>):<br>    <span class="hljs-keyword">if</span> IsPrime(i):<br>        a.append(i)<br>count=<span class="hljs-number">0</span><br><span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(a)):<br>    <span class="hljs-built_in">sum</span>=<span class="hljs-number">0</span><br>    j=k<br>    <span class="hljs-keyword">while</span> <span class="hljs-built_in">sum</span>&lt;n <span class="hljs-keyword">and</span> j&lt;<span class="hljs-built_in">len</span>(a):<br>        <span class="hljs-built_in">sum</span>+=a[j]<br>        j+=<span class="hljs-number">1</span><br>    <span class="hljs-keyword">if</span> <span class="hljs-built_in">sum</span>==n:<br>        count+=<span class="hljs-number">1</span><br><span class="hljs-built_in">print</span>(count)   <br></code></pre></td></tr></table></figure>

<h2 id="四、Python编程之算法岗笔试题"><a href="#四、Python编程之算法岗笔试题" class="headerlink" title="四、Python编程之算法岗笔试题"></a>四、Python编程之算法岗笔试题</h2><h3 id="1、找零钱的所有可能数"><a href="#1、找零钱的所有可能数" class="headerlink" title="1、找零钱的所有可能数"></a>1、找零钱的所有可能数</h3><p><strong>对于1-100之间任意钱，换成等值的10元、5元、2元、1元的小钞票，编程输出所有可能的总数</strong></p>
<p><strong>问题分析</strong><br>对于零钱n，条件x * 1 + y * 2 + z * 5 + m * 10 &#x3D; n，找出符合条件的（x,y,z,m）的总数。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment">#对于1-100之间任意钱，换成等值的10元、5元、2元、1元的小钞票</span><br><span class="hljs-comment">#编程输出所有可能的总数</span><br><br><span class="hljs-comment">#a代表10元的张数</span><br><span class="hljs-comment">#b代表5元的张数</span><br><span class="hljs-comment">#c代表2元的张数</span><br><span class="hljs-comment">#d代表1元的张数</span><br><br><span class="hljs-comment">#方法：for循环</span><br>count=<span class="hljs-number">0</span><br><span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,<span class="hljs-built_in">int</span>(n/<span class="hljs-number">10</span>)+<span class="hljs-number">1</span>):<br>    <span class="hljs-keyword">for</span> b <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,<span class="hljs-built_in">int</span>(n/<span class="hljs-number">5</span>)+<span class="hljs-number">1</span>):<br>    	<span class="hljs-keyword">for</span> c <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,<span class="hljs-built_in">int</span>(n/<span class="hljs-number">2</span>)+<span class="hljs-number">1</span>):<br>        	<span class="hljs-keyword">for</span> d <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,n+<span class="hljs-number">1</span>):<br>            	<span class="hljs-keyword">if</span> a*<span class="hljs-number">10</span>+b*<span class="hljs-number">5</span>+c*<span class="hljs-number">2</span>+d==n:<br>                	count+=<span class="hljs-number">1</span><br><span class="hljs-keyword">return</span> count<br></code></pre></td></tr></table></figure>
<h3 id="2、重排序列"><a href="#2、重排序列" class="headerlink" title="2、重排序列"></a>2、重排序列</h3><p>给定一个长度为N的序列A1到AN，现在要对序列进行M次操作，每次操作对序列的前若干项进行升序或降序排列，求经过这M次操作后得到的序列。<br>输入描述</p>
<blockquote>
<p>第一行包含两个整数N和M，1≤N，M≤10^5。 第二行包含N个空格隔开的整数A1到AN，1≤Ai≤10^9。<br>接下来M行，每行包含两个整数t和x，0≤t≤1，1≤x≤N。若t&#x3D;0，则表示对A1到Ax进行升序排列；若t&#x3D;1，则表示对A1到Ax进行降序排列。操作执行顺序与输入顺序一致。</p>
</blockquote>
<p>输出描述</p>
<blockquote>
<p>输出N个空格隔开的整数，即经过M次操作后得到的序列。</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python">n,m=<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split())<br>l1=<span class="hljs-built_in">list</span>(<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split()))<br>l2=[]<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(m):<br>    nums=<span class="hljs-built_in">list</span>(<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>,<span class="hljs-built_in">input</span>().split()))<br>    l2.append(nums)<br><span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(l2)):<br>    <span class="hljs-keyword">if</span> l2[j][<span class="hljs-number">0</span>]==<span class="hljs-number">1</span>:<br>        l1[:l2[j][<span class="hljs-number">1</span>]]=<span class="hljs-built_in">sorted</span>(l1[:l2[j][<span class="hljs-number">1</span>]],reverse=<span class="hljs-literal">True</span>)<br>    <span class="hljs-keyword">else</span>:<br>        l1[:l2[j][<span class="hljs-number">1</span>]]=<span class="hljs-built_in">sorted</span>(l1[:l2[j][<span class="hljs-number">1</span>]],reverse=<span class="hljs-literal">False</span>)<br><span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> l1:<br>    <span class="hljs-built_in">print</span>(k,end=<span class="hljs-string">&#x27; &#x27;</span>)<br></code></pre></td></tr></table></figure>

<p>参考：</p>

              
            </div>
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/" class="category-chain-item">人工智能</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%BC%96%E7%A8%8B/">#编程</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>ACM模式之输入输出（Java/Python例题）</div>
      <div>http://example.com/2022/07/30/ACM模式之输入输出（Java_Python例题）/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Qin Zk</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年7月30日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/10/23/%E9%80%9A%E8%BF%87GitHub%20Actions%E7%BB%99%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E6%B5%8B%E8%AF%95%E5%8F%B7%E5%92%8C%E9%92%89%E9%92%89%E7%BE%A4%E5%AE%9A%E6%97%B6%E6%8E%A8%E9%80%81%E6%B6%88%E6%81%AF%EF%BC%88Python%EF%BC%89/" title="通过GitHub Actions给微信公众测试号和钉钉群定时推送消息（Python）">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">通过GitHub Actions给微信公众测试号和钉钉群定时推送消息（Python）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/05/20/%E6%B2%B3%E5%8C%97%E7%9C%81%E7%AC%AC%E4%B8%89%E5%B1%8A%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1B%E9%A2%98%EF%BC%88%E4%BA%8C%E7%AD%89%EF%BC%89%E4%BA%A4%E9%80%9A%E6%A3%80%E6%B5%8B%E5%99%A8%E6%95%B0%E6%8D%AE%E8%B4%A8%E9%87%8F%E6%8E%A7%E5%88%B6%E5%8F%8A%E9%A2%84%E6%B5%8B/" title="河北省第三届研究生数学建模B题（二等）交通检测器数据质量控制及预测">
                        <span class="hidden-mobile">河北省第三届研究生数学建模B题（二等）交通检测器数据质量控制及预测</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  <article id="comments" lazyload>
    
  <div id="lv-container" data-id="city" data-uid="MTAyMC81NjkxOC8zMzM4Mg==">
    <script type="text/javascript">
      Fluid.utils.loadComments('#lv-container', function() {
        Fluid.utils.createScript('https://cdn-city.livere.com/js/embed.dist.js');
      });
    </script>
    <noscript>Please enable JavaScript to view the comments</noscript>
  </div>


  </article>


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  






    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  

  

  

  

  

  

  




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.0/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script>
  (function() {
    var enableLang = CONFIG.code_language.enable && CONFIG.code_language.default;
    var enableCopy = CONFIG.copy_btn;
    if (!enableLang && !enableCopy) {
      return;
    }

    function getBgClass(ele) {
      return Fluid.utils.getBackgroundLightness(ele) >= 0 ? 'code-widget-light' : 'code-widget-dark';
    }

    var copyTmpl = '';
    copyTmpl += '<div class="code-widget">';
    copyTmpl += 'LANG';
    copyTmpl += '</div>';
    jQuery('.markdown-body pre').each(function() {
      var $pre = jQuery(this);
      if ($pre.find('code.mermaid').length > 0) {
        return;
      }
      if ($pre.find('span.line').length > 0) {
        return;
      }

      var lang = '';

      if (enableLang) {
        lang = CONFIG.code_language.default;
        if ($pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2 && $pre.children().hasClass('hljs')) {
          lang = $pre[0].children[0].classList[1];
        } else if ($pre[0].getAttribute('data-language')) {
          lang = $pre[0].getAttribute('data-language');
        } else if ($pre.parent().hasClass('sourceCode') && $pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2) {
          lang = $pre[0].children[0].classList[1];
          $pre.parent().addClass('code-wrapper');
        } else if ($pre.parent().hasClass('markdown-body') && $pre[0].classList.length === 0) {
          $pre.wrap('<div class="code-wrapper"></div>');
        }
        lang = lang.toUpperCase().replace('NONE', CONFIG.code_language.default);
      }
      $pre.append(copyTmpl.replace('LANG', lang).replace('code-widget">',
        getBgClass($pre[0]) + (enableCopy ? ' code-widget copy-btn" data-clipboard-snippet><i class="iconfont icon-copy"></i>' : ' code-widget">')));

      if (enableCopy) {
        Fluid.utils.createScript('https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js', function() {
          var clipboard = new window.ClipboardJS('.copy-btn', {
            target: function(trigger) {
              var nodes = trigger.parentNode.childNodes;
              for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].tagName === 'CODE') {
                  return nodes[i];
                }
              }
            }
          });
          clipboard.on('success', function(e) {
            e.clearSelection();
            e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-copy', 'icon-success');
            setTimeout(function() {
              e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-success', 'icon-copy');
            }, 2000);
          });
        });
      }
    });
  })();
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
